/* ColorTest.java v 1.0.9   11/6/04 7:15 PM
 *
 * BioEra - visual designer for biofeedback (http://www.bioera.net)
 *
 * Copyright (c) 2003-2004 Jarek Foltynski (http://www.foltynski.info)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package bioera.tests;

import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

/**
 * Creation date: (2/25/2004 10:53:54 AM)
 * @author: Jarek Foltynski
 */
public class ColorTest extends JPanel implements MouseListener
{
	Image im;
	int[] pixels;
	int w;
	int h;

    public ColorTest()
    {
	    addMouseListener(this);
    }
    public static void main(String args[])
        throws Exception
    {

        try
        {
            ColorTest t = new ColorTest();
            t.xWindow();
            System.out.println("finished");
        }
        catch(Exception e)
        {
            System.out.println("Error: " + e + "\n\n");
            e.printStackTrace();
        }
    }
	/**
	 * Invoked when the mouse has been clicked on a component.
	 */
public void mouseClicked(java.awt.event.MouseEvent e) {}
	/**
	 * Invoked when the mouse enters a component.
	 */
public void mouseEntered(java.awt.event.MouseEvent e) {}
	/**
	 * Invoked when the mouse exits a component.
	 */
public void mouseExited(java.awt.event.MouseEvent e) {}
	/**
	 * Invoked when a mouse button has been pressed on a component.
	 */
public void mousePressed(java.awt.event.MouseEvent ev) {
	System.out.println("h=" + im.getHeight(null));


	//public void handlesinglepixel(int x, int y, int pixel) {
	//int alpha = (pixel >> 24) & 0xff;
	//int red   = (pixel >> 16) & 0xff;
	//int green = (pixel >>  8) & 0xff;
	//int blue  = (pixel      ) & 0xff;
	// Deal with the pixel as necessary...
	// }

	w = im.getWidth(null);
	h = im.getHeight(null);

	pixels = new int[w * h];

	PixelGrabber pg = new PixelGrabber(im, 0, 0, w, h, pixels, 0, w);
	try {
	    pg.grabPixels();
	} catch (InterruptedException e) {
	    System.err.println("interrupted waiting for pixels!");
	    return;
	}
	if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
	    System.err.println("image fetch aborted or errored");
	    return;
	}

	int r=0,g=0,b=0, c = 0;
	for (int j = 0; j < h; j++) {
		int pixel = pixels[j * w + 2];
		int alpha = (pixel >> 24) & 0xff;
		int red   = (pixel >> 16) & 0xff;
		int green = (pixel >>  8) & 0xff;
		int blue  = (pixel      ) & 0xff;
		if (red != r || g != green || b != blue)
			System.out.println("{" + red + ", " + green + ", " + blue + "},");
		r = red;
		g = green;
		b = blue;
		c++;
	}

	System.out.println("c=" + c);

}
	/**
	 * Invoked when a mouse button has been released on a component.
	 */
public void mouseReleased(java.awt.event.MouseEvent e) {}
public void paint(Graphics g) {
	int t[][] = {
{204, 196, 212},
{204, 204, 212},
{252, 252, 252},
{252, 252, 244},
{252, 252, 236},
{252, 252, 228},
{252, 252, 220},
{252, 252, 212},
{252, 252, 204},
{252, 252, 196},
{252, 252, 188},
{252, 252, 180},
{252, 252, 172},
{252, 252, 164},
{252, 252, 156},
{252, 252, 148},
{252, 252, 140},
{252, 252, 132},
{252, 252, 124},
{252, 252, 116},
{252, 252, 108},
{252, 252, 100},
{252, 252, 92},
{252, 252, 84},
{252, 252, 76},
{252, 252, 68},
{252, 252, 60},
{252, 252, 52},
{252, 252, 44},
{252, 252, 36},
{252, 252, 28},
{252, 252, 20},
{252, 252, 12},
{252, 252, 4},
{252, 244, 4},
{252, 236, 4},
{252, 228, 4},
{252, 220, 4},
{252, 212, 4},
{252, 204, 4},
{252, 196, 4},
{252, 188, 4},
{252, 180, 4},
{252, 172, 4},
{252, 164, 4},
{252, 156, 4},
{252, 148, 4},
{252, 140, 4},
{252, 132, 4},
{252, 124, 4},
{252, 116, 4},
{252, 108, 4},
{252, 100, 4},
{252, 92, 4},
{252, 84, 4},
{252, 76, 4},
{252, 68, 4},
{252, 60, 4},
{252, 52, 4},
{252, 44, 4},
{252, 36, 4},
{252, 28, 4},
{252, 20, 4},
{252, 12, 4},
{252, 4, 4},
{244, 4, 12},
{236, 4, 20},
{228, 4, 28},
{220, 4, 36},
{212, 4, 36},
{212, 4, 44},
{204, 4, 44},
{196, 4, 60},
{188, 4, 68},
{180, 4, 76},
{164, 4, 92},
{180, 4, 76},
{164, 4, 92},
{156, 4, 100},
{148, 4, 100},
{148, 4, 108},
{148, 4, 100},
{148, 4, 108},
{148, 4, 100},
{140, 4, 116},
{132, 4, 124},
{128, 0, 128},
{124, 4, 132},
{128, 0, 128},
{116, 4, 140},
{108, 4, 148},
{100, 4, 148},
{100, 4, 156},
{92, 4, 156},
{84, 4, 172},
{76, 4, 180},
{68, 4, 188},
{60, 4, 196},
{52, 4, 204},
{44, 4, 212},
{36, 4, 212},
{36, 4, 220},
{28, 4, 228},
{4, 4, 228},
{20, 4, 236},
{12, 4, 244},
{4, 4, 252},
{4, 4, 244},
{4, 4, 236},
{4, 4, 228},
{4, 4, 220},
{4, 4, 212},
{4, 4, 204},
{4, 4, 196},
{4, 4, 188},
{4, 4, 180},
{4, 4, 172},
{4, 4, 164},
{4, 4, 156},
{4, 4, 148},
{4, 4, 140},
{4, 4, 132},
{4, 4, 124},
{4, 4, 116},
{4, 4, 108},
{4, 4, 100},
{4, 4, 92},
{4, 4, 84},
{4, 4, 76},
{4, 4, 68},
{4, 4, 60},
{4, 4, 52},
{4, 4, 44},
{4, 4, 36},
{4, 4, 28},
{4, 4, 20},
{4, 4, 12},
{4, 4, 20},
{4, 4, 12},
{4, 4, 4}};

	for (int i = 0; i < t.length; i++){
		Color c = new Color(t[i][0], t[i][1], t[i][2]);
		g.setColor(c);
		g.drawLine(i + 10, 10, i + 10, 100);
	}
}
public void paint1(Graphics g) {
	int n = 200;
	int w = 2;
	int b = w * w;
	for (int k = 0; k < b; k++){
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				Color c = new Color(Color.HSBtoRGB((float)(1.0 * i/n), (float)(1.0 * j/n), (float)(1.0 * (k+1) / b)));
				//Color c = new Color(256 * i/n, 256 * j/n, 256 * k / b);
				g.setColor(c);
				g.drawLine(j + n * (k/w), i + (k%w) * (n+1), j+1 + n * (k/w), i + (k%w) * (n+1));

			}
		}
		g.drawString("" + k, (n+1) * (k/w) + 5, (k%w) * (n+1) + 10);
	}
}
public void paint10(Graphics g) {
	int t[][] = {
		{200, 50}
	};
	//int x = 200, y = 20;
	//for (int i = 0; i < ; i+=0.001){
////		int f = i < x ? i * y / x : (i - x) * (x / y);
		//Color c = new Color(0f, i, i);
		//g.setColor(c);
		//g.drawLine(i + 10, 10, i + 10, 100);
	//}
}
public void paint2(Graphics g) {
	int n = 400;
	int m = 100;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			Color c = new Color(Color.HSBtoRGB((float)(0.5 * j / m + 1.0 * i/n), 0.99f, 0.99f));
			//Color c = new Color(Color.HSBtoRGB((float)(i), 0.99f, 0.99f));
			g.setColor(c);
			g.drawLine(j, i, j+1, i);
		}
	}
}
public void paint3(Graphics g) {
	int n = 255;
	for (int i = 0; i < n; i++){
		Color c = new Color(i, 200, 180);
		g.setColor(c);
		g.drawLine(i, 0, i+1, 200);
	}
}
public void paint4(Graphics g) {
	int n = 1000;
	int m = 100;
	for (int i = 0; i <= n; i++){
		for (int j = 0; j <= m; j++){
			Color c = new Color(Color.HSBtoRGB((float)(0.5 - 1.0 * i/n), 0.5f/*(float)(1.0 * j / m)*/, 0.85f /*(float)(1.0 * j / m)*/));
			//Color c = new Color(Color.HSBtoRGB((float)(i), 0.99f, 0.99f));
			g.setColor(c);
			g.drawLine(i, j, i, j+1);
		}
	}
}
public void paint5(Graphics g) {
	if (im == null)
		im = createImage(400, 400);
	g.drawImage(im, 0, 0, null);
}
public void paint6(Graphics g) {
	int n = 255;
	int k = 1;
	for (int j = 0; j < k; j++){
		for (int i = 0; i < n; i++){
			Color c = new Color(i, j * 255 / k, 255);
			g.setColor(c);
			g.drawLine(i + 260 * j, 10, i + 260 * j, 100);
		}
	}
}
public void paint7(Graphics g) {
	double cool[][] = {
{0.0,	1.0000,1.0000}, {0.0159,0.9841,1.0000}, {0.0317,0.9683,1.0000},{0.0476,0.9524,1.0000},
{0.0635,0.9365,1.0000}, {0.0794,0.9206,1.0000}, {0.0952,0.9048,1.0000}, {0.1111,0.8889,1.0000},
{0.1270,0.8730,1.0000}, {0.1429,0.8571,1.0000}, {0.1587,0.8413,1.0000}, {0.1746,0.8254,1.0000},
{0.1905,0.8095,1.0000}, {0.2063,0.7937,1.0000}, {0.2222,0.7778,1.0000}, {0.2381,0.7619,1.0000},
{0.2540,0.7460,1.0000}, {0.2698,0.7302,1.0000}, {0.2857,0.7143,1.0000}, {0.3016,0.6984,1.0000},
{0.3175,0.6825,1.0000}, {0.3333,0.6667,1.0000}, {0.3492,0.6508,1.0000}, {0.3651,0.6349,1.0000},
{0.3810,0.6190,1.0000}, {0.3968,0.6032,1.0000}, {0.4127,0.5873,1.0000}, {0.4286,0.5714,1.0000},
{0.4444,0.5556,1.0000}, {0.4603,0.5397,1.0000}, {0.4762,0.5238,1.0000}, {0.4921,0.5079,1.0000},
{0.5079,0.4921,1.0000}, {0.5238,0.4762,1.0000}, {0.5397,0.4603,1.0000}, {0.5556,0.4444,1.0000},
{0.5714,0.4286,1.0000}, {0.5873,0.4127,1.0000}, {0.6032,0.3968,1.0000}, {0.6190,0.3810,1.0000},
{0.6349,0.3651,1.0000}, {0.6508,0.3492,1.0000}, {0.6667,0.3333,1.0000}, {0.6825,0.3175,1.0000},
{0.6984,0.3016,1.0000}, {0.7143,0.2857,1.0000}, {0.7302,0.2698,1.0000}, {0.7460,0.2540,1.0000},
{0.7619,0.2381,1.0000}, {0.7778,0.2222,1.0000}, {0.7937,0.2063,1.0000}, {0.8095,0.1905,1.0000},
{0.8254,0.1746,1.0000}, {0.8413,0.1587,1.0000}, {0.8571,0.1429,1.0000}, {0.8730,0.1270,1.0000},
{0.8889,0.1111,1.0000}, {0.9048,0.0952,1.0000}, {0.9206,0.0794,1.0000}, {0.9365,0.0635,1.0000},
{0.9524,0.0476,1.0000}, {0.9683,0.0317,1.0000}, {0.9841,0.0159,1.0000}, {1.0000,0,1.0000}};

double hot[][]={
{0.0417,0,0}, {0.0833,0,0}, {0.1250,0,0}, {0.1667,0,0}, {0.2083,0,0}, {0.2500,0,0},
{0.2917,0,0}, {0.3333,0,0}, {0.3750,0,0}, {0.4167,0,0}, {0.4583,0,0}, {0.5000,0,0},
{0.5417,0,0}, {0.5833,0,0}, {0.6250,0,0}, {0.6667,0,0}, {0.7083,0,0}, {0.7500,0,0},
{0.7917,0,0}, {0.8333,0,0}, {0.8750,0,0}, {0.9167,0,0}, {0.9583,0,0}, {1.0000,0,0},
{1.0000,0.0417,0}, {1.0000,0.0833,0}, {1.0000,0.1250,0}, {1.0000,0.1667,0},
{1.0000,0.2083,0}, {1.0000,0.2500,0}, {1.0000,0.2917,0}, {1.0000,0.3333,0},
{1.0000,0.3750,0}, {1.0000,0.4167,0}, {1.0000,0.4583,0}, {1.0000,0.5000,0},
{1.0000,0.5417,0}, {1.0000,0.5833,0}, {1.0000,0.6250,0}, {1.0000,0.6667,0},
{1.0000,0.7083,0}, {1.0000,0.7500,0}, {1.0000,0.7917,0}, {1.0000,0.8333,0},
{1.0000,0.8750,0}, {1.0000,0.9167,0}, {1.0000,0.9583,0}, {1.0000,1.0000,0},
{1.0000,1.0000,0.0625}, {1.0000,1.0000,0.1250}, {1.0000,1.0000,0.1875},
{1.0000,1.0000,0.2500}, {1.0000,1.0000,0.3125}, {1.0000,1.0000,0.3750},
{1.0000,1.0000,0.4375}, {1.0000,1.0000,0.5000}, {1.0000,1.0000,0.5625},
{1.0000,1.0000,0.6250}, {1.0000,1.0000,0.6875}, {1.0000,1.0000,0.7500},
{1.0000,1.0000,0.8125}, {1.0000,1.0000,0.8750}, {1.0000,1.0000,0.9375},
{1.0000,1.0000,1.0000}};

double rainbow[][] = {
{0,0,0.5625}, {0,0,0.6250}, {0,0,0.6875}, {0,0,0.7500}, {0,0,0.8125},
{0,0,0.8750}, {0,0,0.9375}, {0,0,1.0000},
{0,0.0625,1.0000}, {0,0.1250,1.0000}, {0,0.1875,1.0000}, {0,0.2500,1.0000},
{0,0.3125,1.0000}, {0,0.3750,1.0000}, {0,0.4375,1.0000}, {0,0.5000,1.0000},
{0,0.5625,1.0000}, {0,0.6250,1.0000}, {0,0.6875,1.0000}, {0,0.7500,1.0000},
{0,0.8125,1.0000}, {0,0.8750,1.0000}, {0,0.9375,1.0000}, {0,1.0000,1.0000},
{0.0625,1.0000,1.0000}, {0.1250,1.0000,0.9375}, {0.1875,1.0000,0.8750},
{0.2500,1.0000,0.8125}, {0.3125,1.0000,0.7500}, {0.3750,1.0000,0.6875},
{0.4375,1.0000,0.6250}, {0.5000,1.0000,0.5625}, {0.5625,1.0000,0.5000},
{0.6250,1.0000,0.4375}, {0.6875,1.0000,0.3750}, {0.7500,1.0000,0.3125},
{0.8125,1.0000,0.2500}, {0.8750,1.0000,0.1875}, {0.9375,1.0000,0.1250},
{1.0000,1.0000,0.0625}, {1.0000,1.0000,0}, {1.0000,0.9375,0},
{1.0000,0.8750,0}, {1.0000,0.8125,0}, {1.0000,0.7500,0}, {1.0000,0.6875,0},
{1.0000,0.6250,0}, {1.0000,0.5625,0}, {1.0000,0.5000,0}, {1.0000,0.4375,0},
{1.0000,0.3750,0}, {1.0000,0.3125,0}, {1.0000,0.2500,0}, {1.0000,0.1875,0},
{1.0000,0.1250,0}, {1.0000,0.0625,0}, {1.0000,0,0}, {0.9375,0,0}, {0.8750,0,0},
{0.8125,0,0}, {0.7500,0,0}, {0.6875,0,0}, {0.6250,0,0}, {0.5625,0,0}};


	double t[][] = rainbow;
	int n = t.length;

//	g.drawRect(0, 10, n, 100);
	int x = 1;
	for (int m = 0; m < 3; m++){
		if (m == 0)
			t = cool;
		else if (m == 1)
			t = hot;
		else if (m == 2)
			t = rainbow;
		n = t.length;
		x += 10;
		for (int i = 0; i < n; i++){
			Color c = new Color((float)t[i][0], (float)t[i][1], (float)t[i][2]);
			//Color c = new Color(Color.HSBtoRGB((float)(i), 0.99f, 0.99f));
			g.setColor(c);
			g.drawLine(x, 10, x, 100);
			x++;
		}
	}

//	System.out.println("painted");

}
public void paint8(Graphics g) {
	if (im == null) {
		im = Toolkit.getDefaultToolkit().getImage("c:\\Executables\\Lview\\kolory1.gif");
	}

	g.drawImage(im, 0, 0, null);

	if (pixels != null) {
		for (int j = 0; j < h; j++) {
			int pixel = pixels[j * w + 2];
			int alpha = (pixel >> 24) & 0xff;
			int red   = (pixel >> 16) & 0xff;
			int green = (pixel >>  8) & 0xff;
			int blue  = (pixel      ) & 0xff;
			Color c = new Color(red, green, blue);
			g.setColor(c);
			g.drawLine(50, j, 100, j);
		}

	}
}
public void paint9(Graphics g) {
	int t[][] = {
{204, 196, 212},
{204, 204, 212},
{252, 252, 252},
{252, 252, 244},
{252, 252, 236},
{252, 252, 228},
{252, 252, 220},
{252, 252, 212},
{252, 252, 204},
{252, 252, 196},
{252, 252, 188},
{252, 252, 180},
{252, 252, 172},
{252, 252, 164},
{252, 252, 156},
{252, 252, 148},
{252, 252, 140},
{252, 252, 132},
{252, 252, 124},
{252, 252, 116},
{252, 252, 108},
{252, 252, 100},
{252, 252, 92},
{252, 252, 84},
{252, 252, 76},
{252, 252, 68},
{252, 252, 60},
{252, 252, 52},
{252, 252, 44},
{252, 252, 36},
{252, 252, 28},
{252, 252, 20},
{252, 252, 12},
{252, 252, 4},
{252, 244, 4},
{252, 236, 4},
{252, 228, 4},
{252, 220, 4},
{252, 212, 4},
{252, 204, 4},
{252, 196, 4},
{252, 188, 4},
{252, 180, 4},
{252, 172, 4},
{252, 164, 4},
{252, 156, 4},
{252, 148, 4},
{252, 140, 4},
{252, 132, 4},
{252, 124, 4},
{252, 116, 4},
{252, 108, 4},
{252, 100, 4},
{252, 92, 4},
{252, 84, 4},
{252, 76, 4},
{252, 68, 4},
{252, 60, 4},
{252, 52, 4},
{252, 44, 4},
{252, 36, 4},
{252, 28, 4},
{252, 20, 4},
{252, 12, 4},
{252, 4, 4},
{244, 4, 12},
{236, 4, 20},
{228, 4, 28},
{220, 4, 36},
{212, 4, 36},
{212, 4, 44},
{204, 4, 44},
{196, 4, 60},
{188, 4, 68},
{180, 4, 76},
{164, 4, 92},
{180, 4, 76},
{164, 4, 92},
{156, 4, 100},
{148, 4, 100},
{148, 4, 108},
{148, 4, 100},
{148, 4, 108},
{148, 4, 100},
{140, 4, 116},
{132, 4, 124},
{128, 0, 128},
{124, 4, 132},
{128, 0, 128},
{116, 4, 140},
{108, 4, 148},
{100, 4, 148},
{100, 4, 156},
{92, 4, 156},
{84, 4, 172},
{76, 4, 180},
{68, 4, 188},
{60, 4, 196},
{52, 4, 204},
{44, 4, 212},
{36, 4, 212},
{36, 4, 220},
{28, 4, 228},
{4, 4, 228},
{20, 4, 236},
{12, 4, 244},
{4, 4, 252},
{4, 4, 244},
{4, 4, 236},
{4, 4, 228},
{4, 4, 220},
{4, 4, 212},
{4, 4, 204},
{4, 4, 196},
{4, 4, 188},
{4, 4, 180},
{4, 4, 172},
{4, 4, 164},
{4, 4, 156},
{4, 4, 148},
{4, 4, 140},
{4, 4, 132},
{4, 4, 124},
{4, 4, 116},
{4, 4, 108},
{4, 4, 100},
{4, 4, 92},
{4, 4, 84},
{4, 4, 76},
{4, 4, 68},
{4, 4, 60},
{4, 4, 52},
{4, 4, 44},
{4, 4, 36},
{4, 4, 28},
{4, 4, 20},
{4, 4, 12},
{4, 4, 20},
{4, 4, 12},
{4, 4, 4}};

	for (int i = 0; i < t.length; i++){
		Color c = new Color(t[i][0], t[i][1], t[i][2]);
		g.setColor(c);
		g.drawLine(i + 10, 10, i + 10, 100);
	}
}
public void paintCie(Graphics g) {
/*
 * z = 1 - x - y)
 */
double sp[][] = {
    {0.1741, 0.0050}, {0.1740, 0.0050}, {0.1738, 0.0049}, {0.1736, 0.0049},
    {0.1733, 0.0048}, {0.1730, 0.0048}, {0.1726, 0.0048}, {0.1721, 0.0048},
    {0.1714, 0.0051}, {0.1703, 0.0058}, {0.1689, 0.0069}, {0.1669, 0.0086},
    {0.1644, 0.0109}, {0.1611, 0.0138}, {0.1566, 0.0177}, {0.1510, 0.0227},
    {0.1440, 0.0297}, {0.1355, 0.0399}, {0.1241, 0.0578}, {0.1096, 0.0868},
    {0.0913, 0.1327}, {0.0687, 0.2007}, {0.0454, 0.2950}, {0.0235, 0.4127},
    {0.0082, 0.5384}, {0.0039, 0.6548}, {0.0139, 0.7502}, {0.0389, 0.8120},
    {0.0743, 0.8338}, {0.1142, 0.8262}, {0.1547, 0.8059}, {0.1929, 0.7816},
    {0.2296, 0.7543}, {0.2658, 0.7243}, {0.3016, 0.6923}, {0.3373, 0.6589},
    {0.3731, 0.6245}, {0.4087, 0.5896}, {0.4441, 0.5547}, {0.4788, 0.5202},
    {0.5125, 0.4866}, {0.5448, 0.4544}, {0.5752, 0.4242}, {0.6029, 0.3965},
    {0.6270, 0.3725}, {0.6482, 0.3514}, {0.6658, 0.3340}, {0.6801, 0.3197},
    {0.6915, 0.3083}, {0.7006, 0.2993}, {0.7079, 0.2920}, {0.7140, 0.2859},
    {0.7190, 0.2809}, {0.7230, 0.2770}, {0.7260, 0.2740}, {0.7283, 0.2717},
    {0.7300, 0.2700}, {0.7311, 0.2689}, {0.7320, 0.2680}, {0.7327, 0.2673},
    {0.7334, 0.2666}, {0.7340, 0.2660}, {0.7344, 0.2656}, {0.7346, 0.2654},
    {0.7347, 0.2653}, {0.7347, 0.2653}, {0.7347, 0.2653}, {0.7347, 0.2653},
    {0.7347, 0.2653}, {0.7347, 0.2653}, {0.7347, 0.2653}, {0.7347, 0.2653},
    {0.7347, 0.2653}, {0.7347, 0.2653}, {0.7347, 0.2653}, {0.7347, 0.2653},
    {0.7347, 0.2653}, {0.7347, 0.2653}, {0.7347, 0.2653}, {0.7347, 0.2653},
    {0.7347, 0.2653}};

	for (int i = 0; i < sp.length; i++){
		float b = (float) (1.0 - sp[i][0] - sp[i][1]);
		if (b < 0)
			b = 0f;
		if (b > 1f)
			b = 1f;
		Color c = new Color((float) sp[i][0], (float) sp[i][1], b);
		//Color c = new Color(Color.HSBtoRGB((float)(i), 0.99f, 0.99f));
		g.setColor(c);
		g.drawLine(i + 10, 10, i + 10, 100);
	}
}
public void println(String s) throws Exception {
	System.out.println(s);

	//logFileStream.write((s + "\n").getBytes());
}
public void xWindow() throws Exception{
	try {
		JFrame f = new JFrame();
		f.setBounds(10, 10, 450, 450);
		f.setContentPane(this);
                f.setVisible(true);
		//f.show();
/*
		while (im == null)
			Thread.sleep(10);

		Graphics g = im.getGraphics();
		int n = 400;
		int m = 400;
		Color c = new Color(Color.HSBtoRGB(0.9f, 0.5f, 0.85f));
		long time = System.currentTimeMillis();
		for (int i = 0; i <= n; i++){
			for (int j = 0; j <= m; j++){
				//Color c = new Color(Color.HSBtoRGB((float)(0.5 - 1.0 * i/n), 0.5f, 0.85f ));
				//Color c = new Color(Color.HSBtoRGB((float)(i), 0.99f, 0.99f));
				g.setColor(c);
				g.drawLine(j, i, j+1, i);
			}
			repaint();
		}
		System.out.println("time=" + (System.currentTimeMillis() - time));
*/
	} catch(Exception e) {
        System.out.println("Error: " + e + "("+new Date()+")\n\n");
        e.printStackTrace();
    }
}
}
